package com.yanqu.road.server.cmd.activity.xiuxian;

import com.yanqu.road.entity.activity.xiuxian.config.XiuXianConfig;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.XiuXianProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.xiuxian.XiuXianModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.xiuxian.XiuXianMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_XIU_XIAN_GET_PLACE_INFO, desc = "获取房间信息")
public class XiuXianGetPlaceInfoCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        XiuXianProto.XiuXianGetPlaceInfoReqMsg reqMsg = XiuXianProto.XiuXianGetPlaceInfoReqMsg.parseFrom(packet.getBytes());
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        XiuXianConfig config = XiuXianMgr.getConfig();
        if (config == null || !ActivityMgr.activityInShowTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        ret = player.getModule(XiuXianModule.class).getPlaceInfo();

    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            XiuXianProto.XiuXianGetPlaceInfoRespMsg.Builder respMsg = XiuXianProto.XiuXianGetPlaceInfoRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_XIU_XIAN_GET_PLACE_INFO, respMsg);
        }
    }
}
